﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
 


namespace MX.Core.Caching.Memcached
{
    /// <summary>
    /// 对象转二进制
    /// </summary>
    public class BinaryFormatter
    { 
        static public byte[] Serialize(object obj)
        {
            var jsv = JsonConvert.SerializeObject(obj);
            return Encoding.UTF8.GetBytes(jsv);
        }

        static public T Deserialize<T>(byte[] memStream)
        {
            return Deserialize<T>(Encoding.UTF8.GetString(memStream));
        }

        public static T Deserialize<T>(string jsvString)
        {
            return JsonConvert.DeserializeObject<T>(jsvString);
        }


 
    }
}
